package com.example.meitao.ui;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Window;
import android.widget.ImageView;

import com.example.meitao.R;
import com.example.meitao.adapter.MyPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class LinkActivity extends AppCompatActivity {

    private Toolbar mToolbar;
    private ViewPager mViewPager;
    private List<ImageView> mImageViewList;
    private PagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_link);
        initView();
        initData();
        setData();
    }

    private void setData() {
        mViewPager.setAdapter(mAdapter);
    }

    private void initData() {
        mImageViewList = new ArrayList<>();
        mAdapter = new MyPagerAdapter(mImageViewList);
        for (int i = 0; i < 2; i++) {
            ImageView iv = new ImageView(this);
            ViewPager.LayoutParams params =new ViewPager.LayoutParams();
            params.height= ViewPager.LayoutParams.MATCH_PARENT;
            params.width=ViewPager.LayoutParams.MATCH_PARENT;
            iv.setLayoutParams(params);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            if(i==0) {
                iv.setImageResource(R.mipmap.dis_first);
            }else{
                iv.setImageResource(R.mipmap.dis_second);
            }
            mImageViewList.add(iv);
            mAdapter.notifyDataSetChanged();
        }
    }

    private void initView() {
        mToolbar = (Toolbar) findViewById(R.id.tb_link);
        setSupportActionBar(mToolbar);
        mViewPager = (ViewPager) findViewById(R.id.vp_link);
    }
}
